package com.weipu.common.facade.model;

import org.json.JSONObject;

import com.weipu.common.constants.ServerConstant;

import android.os.Parcel;
import android.os.Parcelable;
import android.os.Parcelable.Creator;

public class SimpleCreditCard implements Parcelable {

	private String id;

	private String cardHolder;

	private String firstSixDigits;

	private String lastFourDigits;

	private String token;

	private String tokenStatus;

	private String MID;

	private String notes;
	
	private String cardNum;
	
	private String cardType;

	@SuppressWarnings("unchecked")
	public SimpleCreditCard(Parcel source) {
		id = source.readString();
		cardNum = source.readString();
		cardHolder = source.readString();
		firstSixDigits = source.readString();
		lastFourDigits = source.readString();
		token = source.readString();
		tokenStatus = source.readString();
		MID = source.readString();
		notes = source.readString();
		cardType = source.readString();
	}

	public SimpleCreditCard() {
	}

	public static final Parcelable.Creator<SimpleCreditCard> CREATOR = new Creator<SimpleCreditCard>() {

		@Override
		public SimpleCreditCard[] newArray(int size) {
			// TODO Auto-generated method stub
			return new SimpleCreditCard[size];
		}

		@Override
		public SimpleCreditCard createFromParcel(Parcel source) {
			// TODO Auto-generated method stub
			return new SimpleCreditCard(source);
		}
	};

	@Override
	public int describeContents() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public void writeToParcel(Parcel parcel, int arg1) {
		parcel.writeString(id);
		parcel.writeString(cardNum);
		parcel.writeString(cardHolder);
		parcel.writeString(firstSixDigits);
		parcel.writeString(lastFourDigits);
		parcel.writeString(token);
		parcel.writeString(tokenStatus);
		parcel.writeString(MID);
		parcel.writeString(notes);
		parcel.writeString(cardType);
	}
	
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getCardHolder() {
		return cardHolder;
	}

	public void setCardHolder(String cardHolder) {
		this.cardHolder = cardHolder;
	}

	public String getFirstSixDigits() {
		return firstSixDigits;
	}

	public void setFirstSixDigits(String firstSixDigits) {
		this.firstSixDigits = firstSixDigits;
	}

	public String getLastFourDigits() {
		return lastFourDigits;
	}

	public void setLastFourDigits(String lastFourDigits) {
		this.lastFourDigits = lastFourDigits;
	}

	public String getToken() {
		return token;
	}

	public void setToken(String token) {
		this.token = token;
	}

	public String getTokenStatus() {
		return tokenStatus;
	}

	public void setTokenStatus(String tokenStatus) {
		this.tokenStatus = tokenStatus;
	}

	public String getMID() {
		return MID;
	}

	public void setMID(String mID) {
		MID = mID;
	}

	public String getNotes() {
		return notes;
	}

	public void setNotes(String notes) {
		this.notes = notes;
	}

	public String getCardNum() {
		return cardNum;
	}

	public void setCardNum(String cardNum) {
		this.cardNum = cardNum;
	}

	public String getCardType() {
		return cardType;
	}

	public void setCardType(String cardType) {
		this.cardType = cardType;
	}

	public static SimpleCreditCard jsonObjectSimpleCreditCard(JSONObject jsonObject){
		SimpleCreditCard sCreditCard=new SimpleCreditCard();
		if(jsonObject!=null){
			if (jsonObject.optString(ServerConstant.CreditCard.CREDITCARD_ID)!= JSONObject.NULL
					&& !jsonObject.isNull(ServerConstant.CreditCard.CREDITCARD_ID)) {
				sCreditCard.setId(jsonObject
						.optString(ServerConstant.CreditCard.CREDITCARD_ID));
			}
			if (jsonObject.optString(ServerConstant.CreditCard.CREDITCARD_CARDHOLDER)!= JSONObject.NULL
					&& !jsonObject.isNull(ServerConstant.CreditCard.CREDITCARD_CARDHOLDER)) {
				sCreditCard.setCardHolder(jsonObject
						.optString(ServerConstant.CreditCard.CREDITCARD_CARDHOLDER));
			}
			if (jsonObject.optString(ServerConstant.CreditCard.CREDITCARD_CARD_NUM)!= JSONObject.NULL
					&& !jsonObject.isNull(ServerConstant.CreditCard.CREDITCARD_CARD_NUM)) {
				sCreditCard.setCardNum(jsonObject
						.optString(ServerConstant.CreditCard.CREDITCARD_CARD_NUM));
			}
			if (jsonObject.optString(ServerConstant.CreditCard.CREDITCARD_CARDTYPE)!= JSONObject.NULL
					&& !jsonObject.isNull(ServerConstant.CreditCard.CREDITCARD_CARDTYPE)) {
				sCreditCard.setCardType(jsonObject
						.optString(ServerConstant.CreditCard.CREDITCARD_CARDTYPE));
			}
			if (jsonObject.optString(ServerConstant.CreditCard.CREDITCARD_FIRSTSIXDIGITS)!= JSONObject.NULL
					&& !jsonObject.isNull(ServerConstant.CreditCard.CREDITCARD_FIRSTSIXDIGITS)) {
				sCreditCard.setFirstSixDigits(jsonObject
						.optString(ServerConstant.CreditCard.CREDITCARD_FIRSTSIXDIGITS));
			}
			if (jsonObject.optString(ServerConstant.CreditCard.CREDITCARD_LASTFOURDIGITS)!= JSONObject.NULL
					&& !jsonObject.isNull(ServerConstant.CreditCard.CREDITCARD_LASTFOURDIGITS)) {
				sCreditCard.setLastFourDigits(jsonObject
						.optString(ServerConstant.CreditCard.CREDITCARD_LASTFOURDIGITS));
			}
			if (jsonObject.optString(ServerConstant.CreditCard.CREDITCARD_TOKEN)!= JSONObject.NULL
					&& !jsonObject.isNull(ServerConstant.CreditCard.CREDITCARD_TOKEN)) {
				sCreditCard.setToken(jsonObject
						.optString(ServerConstant.CreditCard.CREDITCARD_TOKEN));
			}
			if (jsonObject.optString(ServerConstant.CreditCard.CREDITCARD_MID)!= JSONObject.NULL
					&& !jsonObject.isNull(ServerConstant.CreditCard.CREDITCARD_MID)) {
				sCreditCard.setMID(jsonObject
						.optString(ServerConstant.CreditCard.CREDITCARD_MID));
			}
			if (jsonObject.optString(ServerConstant.CreditCard.CREDITCARD_NOTES)!= JSONObject.NULL
					&& !jsonObject.isNull(ServerConstant.CreditCard.CREDITCARD_NOTES)) {
				sCreditCard.setNotes(jsonObject
						.optString(ServerConstant.CreditCard.CREDITCARD_NOTES));
			}
			if (jsonObject.optString(ServerConstant.CreditCard.CREDITCARD_TOKENSTATUS)!= JSONObject.NULL
					&& !jsonObject.isNull(ServerConstant.CreditCard.CREDITCARD_TOKENSTATUS)) {
				sCreditCard.setTokenStatus(jsonObject
						.optString(ServerConstant.CreditCard.CREDITCARD_TOKENSTATUS));
			}
		}
		
		return sCreditCard;
	}

}
